/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.max.oti.system.util;

import com.max.oti.system.dao.interfac.IChargeDao;
import com.max.oti.system.dao.interfac.IStateDao;
import com.max.oti.system.dao.interfac.ITypeComissionDao;
import com.max.oti.system.dao.interfac.ITypeUserDao;
import com.max.oti.system.model.Charge;
import com.max.oti.system.model.State;
import com.max.oti.system.model.TypeComission;
import com.max.oti.system.model.TypeUser;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 *
 * @author max
 */
public class Clazz {

    @Autowired
    @Qualifier("stateDao")
    IStateDao stateDao;
    @Autowired
    @Qualifier("chargeDao")
    IChargeDao chargeDao;
    @Autowired
    @Qualifier("typeComissionDao")
    ITypeComissionDao typeComissionDao;
    @ManagedProperty("#{typeUserDao}")
    ITypeUserDao typeUserDao;
    
    public State STATE(String name, String nameEntity) {
        String HQL = "select s.id as id, s.name as name, s.nameEntity as nameEntity, s.detail as detail"
                + " from State s where s.name='(name)' and s.nameEntity='(nameEntity)'";
        HQL = HQL.replace("(name)", name.toUpperCase());
        HQL = HQL.replace("(nameEntity)", nameEntity);

        try {
            List<State> listState = stateDao.listHQL(HQL, State.class);
            if (listState.isEmpty()) {
                State state = new State();
                state.setName(name);
                state.setNameEntity(nameEntity);
                state.setDetail(name);
                int idState = stateDao.save(state);
                state.setId(idState);
                return state;
            } else {
                return listState.get(0);
            }
        } catch (Exception ex) {
            Logger.getLogger(Clazz.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public Charge CHARGE(String name) {
        String HQL = "select c.id as id, c.name as name from Charge c where c.name='(name)'";
        HQL = HQL.replace("(name)", name);
        try {
            List<Charge> listCharge = chargeDao.listHQL(HQL, Charge.class);
            if(listCharge.isEmpty()) {
                Charge ch = new Charge();
                ch.setFunctions(name);
                ch.setName(name);
                int idCharge = chargeDao.save(ch);
                ch.setId(idCharge);
                return ch;
            } else {
                return listCharge.get(0);
            }
        } catch (Exception ex) {
            Logger.getLogger(Clazz.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    
    public TypeComission TYPE_COMISSION(String name) {
        String HQL = "select c.id as id, c.name as name from TypeComission c where c.name='(name)'";
        HQL = HQL.replace("(name)", name);
        try {
            List<TypeComission> listCharge = typeComissionDao.listHQL(HQL, TypeComission.class);
            if(listCharge.isEmpty()) {
                TypeComission ty = new TypeComission();
                ty.setName(name);
                int idTC = typeComissionDao.save(ty);
                ty.setId(idTC);
                System.out.println(idTC);
                return ty;
            } else {
                return listCharge.get(0);
            }
        } catch (Exception ex) {
            Logger.getLogger(Clazz.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    
    public TypeUser _TYPE_USER(String name) {
        String HQL = "select c.id as id, c.name as name, c.detail as detail from TypeUser c where c.name='(name)'";
        HQL = HQL.replace("(name)", name);
        try {
            List<TypeUser> listCharge = typeUserDao.listHQL(HQL, TypeUser.class);
            if(listCharge.isEmpty()) {
                TypeUser ty = new TypeUser();
                ty.setName(name);
                ty.setDetail(name);
                int idTC = typeUserDao.save(ty);
                ty.setId(idTC);
                return ty;
            } else {
                return listCharge.get(0);
            }
        } catch (Exception ex) {
            Logger.getLogger(Clazz.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    
    public static class CHARGE {
        public static class Name {
            public static final String SECRETARIO = "SECRETARIO";
        }
    }
    
    public static class STATE {

        /**
         * Primer parametro
         */
        public static class Name {

            /**
             * User,SchedulePractice
             */
            public static final String ACTIVO = "ACTIVO";
            /**
             * User,SchedulePractice
             */
            public static final String INACTIVO = "INACTIVO";
            /**
             *
             */
            public static final String INICIADO = "INICIADO";
            /**
             * HistoryPractice 1
             */
            public static final String INSCRIPCION_DE_PRACTICAS = "PRÁCTICA INSCRITA";
            /**
             * HistoryPractice 2
             */
            public static final String ASIGNACION_DE_ASESOR_Y_RESOLUCION = "AUTORIZADO Y ASESOR ASIGNADO";
            /**
             * HistoryPractice 3
             */
            public static final String SUPERVISION = "SUPERVISIÓN ASIGNADA";
            /**
             * HistoryPractice 4
             */
            public static final String ANULACION_POR_SUPERVICION = "ANULADO POR SUPERVISIÓN";
            /**
             * HistoryPractice 5
             */
            public static final String AMPLIACION = "PRACTICA AMPLIADA";
            /**
             * HistoryPractice 6, ReportPractice
             */
            public static final String ENTREGA_DE_INFORME = "INFORME ENTREGADO";
            /**
             * HistoryPractice 7
             */
            public static final String ANULACION_POR_ENTREGA_DE_INFORME_FUERA_DE_FECHA = "AnulaDO por Entrega de Informe Fuera de Fecha".toUpperCase();
            /**
             * HistoryPractice 8
             */
            public static final String PARA_SUSTENTAR = "Para Sustentar".toUpperCase();
            /**
             * HistoryPractice 9
             */
            public static final String APROVADO = "PRACTICA APROBADA";
            
            /**
             * HistoryPractice 11
             */
            public static final String DESAPROVADO = "PRACTICA DESAPROBADA";
            /**
             * HistoryPractice 12
             */
            public static final String DESAPROVADO_CON_CORRECION = "PRACTICA DesaproBadA con CorrecciOnES".toUpperCase();
            
            /**
             * HistoryPractice 13
             */
            public static final String PRACTICA_CULMINADA = "PRACTICA CULMINADA";
            
            /**
             * ReportPractice
             */
            public static final String INFORME_FINAL_ETREGADO = "INFORME FINAL ENTREGADO";
        }

        /**
         * Segundo parametro.
         */
        public static class Entity {

            public static final String USER = "User";
            public static final String SCHEDULE_PRACTICE = "SchedulePractice";
            public static final String HISOTRY_PRACTICE = "HistoryPractice";
            public static final String REPORT_PRACTICE = "ReportPractice";
        }
    }
    
    public static class _TYPECOMISSION {
        public static final String SGT = "Seguimiento de Grados y Titulos";
        public static final String SPPP = "Seguimiento de Practicas Pre Profesionales";
        public static final String ADMIN = "Administrador";
    }
    
    public static class _TYPEUSER {
        public static final String ADMINISTRADOR = "Administrador";
    }
}
